/**An axis aligned bounding box.*/
public class b2AABB extends b2AllocationGuard {

	b2AABB(int addr) {
		super(addr);
	}

	@Override
	public void release() {
		if ( address != 0 ) {
			jni_b2AABB_release(address);
		}
		super.release();
	}

	/**default finalructor*/
	public b2AABB() {
		address = jni_b2AABB();
	}

	/**Verify that the bounds are sorted.*/
	public boolean IsValid() {
		return jni_b2AABB_IsValid(address);
	}

	/**
	 * Get the center of the AABB.
	 * The underlying C++ code just return a temporary object which
	 * is allocated from the stack. But, on the Java end, we have to
	 * allocate from the heap, and create a new b2Vec2 object for safty.
	 **/
	public b2Vec2 GetCenter() {
		return new b2Vec2(jni_b2AABB_GetCenter(address));
	}

	/**
	 * Get the extents of the AABB (half-widths).
	 **/
	public b2Vec2 GetExtents() {
		return new b2Vec2(jni_b2AABB_GetExtents(address));
	}

	/**Get the perimeter length*/
	public float GetPerimeter() {
		return jni_b2AABB_GetPerimeter(address);
	}

	/**Combine an AABB into this one.*/
	public void Combine(final b2AABB aabb) {
		jni_b2AABB_Combine(address, aabb.address);
	}

	/**Combine two AABBs into this one.*/
	public void Combine(final b2AABB aabb1, final b2AABB aabb2) {
		jni_b2AABB_Combine(address, aabb1.address, aabb2.address);
	}

	/**Does this aabb contain the provided AABB.*/
	public boolean Contains(final b2AABB aabb) {
		return jni_b2AABB_Contains(address, aabb.address);
	}

	public boolean RayCast(b2RayCastOutput output, final b2RayCastInput input) {
		return jni_b2AABB_RayCast(address, output.address, input.address);
	}

	// jni wrappers
	private native static void jni_b2AABB_release(int me);
	private native static int jni_b2AABB();
	private native static boolean jni_b2AABB_IsValid(int me);
	private native static int jni_b2AABB_GetCenter(int me); // will create a java object
	private native static int jni_b2AABB_GetExtents(int me);
	private native static float jni_b2AABB_GetPerimeter(int me);
	private native static void jni_b2AABB_Combine(int me, int aabb);
	private native static void jni_b2AABB_Combine(int me, int aabb1, int aabb2);
	private native static boolean jni_b2AABB_Contains(int me, int aabb);
	private native static boolean jni_b2AABB_RayCast(int me, int output, int input);
}
